package com.dycong.common.reflect.aop;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileInputStream;
import java.util.List;

/**
 * Created by dycong on 2016/12/12.
 */
public class Test {
    public static void main(String[] args) {
        annotation();
//        property();
//    annotationBefore();
//        annotationAfter();
//        anno();
    }


    /*注解式*/
    public static void annotation() {
        ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImpl");

        greeting.sayLove("", "");
    }

    /*配置式*/
    public static void property() {
        ApplicationContext context = new ClassPathXmlApplicationContext("aop1.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImpl1");
        greeting.sayLove("", "");
    }


    public static void annotationBefore() {
        ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImplBefore");
        greeting.sayLove("", "");
    }


    public static void annotationAfter() {
        ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImplAfter");
        greeting.sayLove("", "");
    }

    public static void anno(){
        ApplicationContext context = new ClassPathXmlApplicationContext("aop2.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImplNew");
        greeting.sayLove("girl", "A");
    }

    public void testDom4j(){
        try (FileInputStream inputStream=new FileInputStream("F:\\Github\\wechet\\src\\main\\resources\\aop.xml")){
            Document document=new SAXReader().read(inputStream);
            List<Element> elements=document.getRootElement().elements();

            System.out.println(elements);
        }catch (Exception e){
            System.out.println("////////////////");
        }
    }

    public void variable(){
        ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
        Greeting greeting = (Greeting) context.getBean("greetingImplBefore");
    }
}
